<?php

/**
 * Class for viewing the CSS stylesheet for a page.
 * The constructor inputs all the page data
 *
 * @author Ian Clarence ian.clarence@gmail.com
 */ 
abstract class ViewStylesheet extends Component {
    
    /**
     * Background colour.
     */
    const BACKGROUND_COLOUR = BLUE4;
    
    /**
     * Text background colour.
     */
    const TEXT_BACKGROUND_COLOUR = BLUE1;
    
    /**
     * Font family.
     */
    const FONT_FAMILY = 'Arial, Helvetica, sans-serif';
    
    /**
     * Font size.
     */
    const FONT_SIZE = BODY_FONT_SIZE;
    
    /**
     * Text colour.
     */
    const TEXT_COLOUR = BLUE4;
    
    /**
     * Link colour.
     */
    const LINK_COLOUR = RED1;
    
    /**
     * Hover link colour.
     */
    const HOVER_LINK_COLOUR = GREEN4;
    
    /**
     * Page widths. 
     */
    const PAGE_WIDTH = 1000;
    const LEFT_NAVIGATION_WIDTH = 200;
    const CONTENT_WIDTH = 760;
    const FOOTER_HEIGHT = 150;
    
    /**
     * Minimum page height.
     */
    const MIN_PAGE_HEIGHT = 1700;
    const MIN_CONTENT_HEIGHT = 500;
    
    /**
     * The stylesheet is made up solely of an array of CSS rules.
     * 
     * @var array
     */
    protected $viewCssRules = array();

    /**
     * The constructor.
     *
     * @param array $fields
     */
    public function __construct(array $fields = array()) {        
        parent::__construct($fields);
    }
    
    /**
     * Adding a CSS rule to the stylesheet.
     * 
     * @param ViewCssRule $viewCssRule 
     */
    protected function addCssRule($viewCssRule) {
        if ($viewCssRule instanceof ViewCssRule) {
            $this->viewCssRules[count($this->viewCssRules)] = $viewCssRule;
        }
    }
    
    /**
     * Adding an array of CSS rules to the stylesheet.
     * 
     * @param array $viewCssRules 
     */
    protected function addCssRules($viewCssRules) {
        if (is_array($viewCssRules)) {
            foreach ($viewCssRules as $viewCssRule) {
                $this->addCssRule($viewCssRule);
            }
        }
    }
    
    /**
     * Viewing the whole stylesheet.
     * 
     * @return string 
     */
    public function view() {
        $output = '';
        if (is_array($this->viewCssRules)) {
            foreach ($this->viewCssRules as $viewCssRule) {
                if ($viewCssRule instanceof ViewCssRule) {
                    $output .= $viewCssRule->view() . "\n";
                }
            }
        }
        return $output;
    }
    
}